<template>
    <elm-table v-show="historyExist" v-loading="loading" :data="logList" :default-expand-all="true" :show-index="false" :page-size="9999" style="height: 100%;">
      <el-table-column prop="nodeins_title" label="节点" min-width="90px" align="center" show-overflow-tooltip></el-table-column>
      <el-table-column prop="status_str" label="状态" width="70px" align="center"></el-table-column>
      <el-table-column prop="person_names" label="办理人" width="70px"  align="center"></el-table-column>
      <el-table-column prop="status_time_str" label="状态时间" width="160px" align="center"></el-table-column>
      <el-table-column v-if="pushBackExist" prop="pb_text" label="退回意见" width="120px" align="center" show-overflow-tooltip></el-table-column>
    </elm-table>
</template>

<script>
export default {
  data() {
    return {
      loading:true,

      historyExist:[],
      logList:[],

      pData:{'data_id':null,'flow_code':null},

      pushBackExist:false,
    }
  },
  props: {
    flow_code: { type: String, default: null },
    data_id: { type: String, default: null },
  },
  watch: {
    flow_code: {
      async handler(newval, oldval) {
        if (newval != null && newval!='') {
          this.load();
        }
      },
      immediate: true
    },
    data_id: {
      async handler(newval, oldval) {
        if (newval != null && newval!='') {
          this.load();
        }
      },
      immediate: true
    },
  },
  created() {},
  mounted() {
    this.load();
  },
  methods: {
    async load() {
      if(this.pData.data_id==this.data_id && this.pData.flow_code==this.flow_code){return;}

      this.historyExist = false;
      this.pushBackExist = false;
      this.logList = [];

      if(this.em(this.data_id) || this.em(this.flow_code)){return;}
      console.log(this.data_id);

      this.historyExist = true;
      this.loading=true;

      this.pData.data_id=this.data_id;
      this.pData.flow_code=this.flow_code;
      let dataList = await elm.post('/system/login/flow/GetFlowinsNodeLog', this.pData);
      if(dataList.length>0){
        for(let i=0;i<dataList.length;i++){
          let item = dataList[i];
          if(!this.em(item.status_time)){
            item['status_time_str'] = item.status_time.replace('T','  ');
          }
          if(!this.em(item.status)){
            item['status_str'] = '';
            if(item.status=='running'){item.status_str='运行中';}
            if(item.status=='completed'){item.status_str='完成';}
            if(item.status=='waiting'){item.status_str='退回等待';this.pushBackExist = true;}
          }
        }
        this.logList = dataList;
      }
      this.loading=false;
    },

    em: function (s) {
      if (s == null || s == '') { return true; }
      else { return false; }
    },
  }
}
</script>